/*
 * Printer.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.print;

import com.cute4j.core.AbstractDisposable;
import com.cute4j.swing.Swing;


/**
 * Printer.
 *
 * @cute4j.native
 *    generate="header"
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class Printer extends AbstractDisposable {

// Static Initialization. ------------------------------------------------------

  static {
    Swing.initialize();
    _initialize();
  }

// Package-Private Fields. -----------------------------------------------------

  long _delegate;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new Printer object.
   */
  public Printer() {
    _delegate = _create(); // NOPMD
    if (_delegate == 0) {
      throw new OutOfMemoryError("Printer creation failed");
    }
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Displays page setup dialog.
   */
  public void pageDialog() {
    disposedCheck();
    _pageDialog(_delegate);
  }

  /**
   * Displays printer dialog.
   *
   * @return <tt>true</tt> if dialog is accepted by the user
   */
  public boolean printerDialog() {
    disposedCheck();
    return _printerDialog(_delegate);
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  protected final void disposeObject() {
    if (_delegate != 0) {
      _destroy(_delegate);
      _delegate = 0;
    }
  }

// Package-Private Native Methods. ---------------------------------------------

  native long _create();

  native void _destroy(long delegate);

  native void _pageDialog(long delegate);

  native boolean _printerDialog(long delegate);

// Private Static Native Methods. ----------------------------------------------

  private static native void _initialize();

}
